﻿using System;

namespace Aspire.Domain.Core
{
    public abstract class BaseEntity<TId>
    {
        public virtual TId Id { get; set; }

        public virtual DateTime CreatedAt { get; set; }

        public virtual DateTime UpdatedAt { get; set; }

        public virtual bool IsDelete { get; set; }

        public virtual DateTime DeleteAt { get; set; }

        public static bool operator ==(BaseEntity<TId> a, BaseEntity<TId> b)
        {
            if (a == null)
                return b == null;
            if (b == null)
                return a == null;
            return a.Id.Equals(b.Id);
        }

        public static bool operator !=(BaseEntity<TId> a, BaseEntity<TId> b)
        {
            return !(a == b);
        }

        public override bool Equals(object obj)
        {
            if (obj is BaseEntity<TId> baseEntity)
                return baseEntity == this;
            return false;
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        public override string ToString()
        {
            return this.ToJson();
        }
    }
}
